package com.hungryinlindholmen;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Creates an ownerDb object depending on what parameters are received and
 * forwards it to ownerresults.jsp.
 * 
 * @author Ludvig Gee
 * 
 */

@WebServlet("/OwnerServlet")
public class OwnerServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doPost(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {

	OwnerDb sR = new OwnerDb(request.getParameter("radioButton"),
		(String) request.getSession().getAttribute("restID"));
	request.setAttribute("OwnerDb", sR);
	request.setAttribute("table", sR.getTable());
	request.setAttribute("option", sR.getOption());
	request.getSession().setAttribute("DBConnection", sR.getCon());
	request.getSession().setAttribute("restID",
		request.getSession().getAttribute("restID"));
	RequestDispatcher dispatcher = request
		.getRequestDispatcher("ownerresults.jsp");
	dispatcher.forward(request, response);
	return;

    }

}
